#include<iostream>

//单例模式：一个类只创建一个对象
//懒汉式：对象在调用时进行构建
//饿汉式：程序开始时就构建
//懒汉比饿汉更灵活


//懒汉式
class singleton
{
public:
    static singleton* getInstance()
    {
       if(s==nullptr)
       {
            s=new singleton;
       }
       return s;
    }


private:
    //构造函数私有化
    singleton(){}   
    static singleton *s;


};
singleton *singleton::s=nullptr;


//饿汉式
class singleton
{
public:
    static singleton* getInstance()
    {
        return s;
    }


private:
    //构造函数私有化
    singleton(){}   
    static singleton *s;


};
singleton *singleton::s=new singleton;


class singleton
{
public:
    static singleton* getInstance()
    {
        static singleton s;
        return &s;

    }


private:
    //构造函数私有化
    singleton(){}

};


int main()
{
    



    printf("%p %p %p",t1,t2,t3);





    return 0;
}